package org.example.system.controller;

import org.example.system.entity.ScenicSpot;
import org.example.system.service.RouteSpotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/route-spot")
public class RouteSpotController {
    @Autowired
    private RouteSpotService routeSpotService;

    // 查询某路线下所有景点
    @GetMapping("/scenic/{routeId}")
    public List<ScenicSpot> getScenicSpotsByRouteId(@PathVariable Long routeId) {
        return routeSpotService.getScenicSpotsByRouteId(routeId);
    }

    // 为路线添加景点
    @PostMapping("/add")
    public Map<String, Object> addScenicSpotToRoute(@RequestBody Map<String, Long> params) {
        Long routeId = params.get("routeId");
        Long scenicSpotId = params.get("scenicSpotId");
        int row = routeSpotService.addScenicSpotToRoute(routeId, scenicSpotId);
        Map<String, Object> result = new HashMap<>();
        result.put("success", row > 0);
        result.put("message", row > 0 ? "添加成功" : "添加失败");
        return result;
    }

    // 从路线移除景点
    @PostMapping("/remove")
    public Map<String, Object> removeScenicSpotFromRoute(@RequestBody Map<String, Long> params) {
        Long routeId = params.get("routeId");
        Long scenicSpotId = params.get("scenicSpotId");
        int row = routeSpotService.removeScenicSpotFromRoute(routeId, scenicSpotId);
        Map<String, Object> result = new HashMap<>();
        result.put("success", row > 0);
        result.put("message", row > 0 ? "移除成功" : "移除失败");
        return result;
    }
} 